package com.hk.Mgr.web.controller;

import com.hk.base.BaseCtrl;
import com.hk.base.ResponseBase;
import com.hk.commons.Chart.BrokenLineChartMsg;
import com.hk.commons.Chart.ComparisonChartMsg;
import com.hk.commons.ResultCode;
import com.hk.commons.entity.Bank;
import com.hk.service.sys.IChart;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author lemon 用户实现类
 */
@Controller
@RequestMapping(value = BaseCtrl.MgrRootPath + "/chartCtrl")
public class ChartCtrl extends BaseCtrl {

	private Logger logger = LoggerFactory.getLogger(ChartCtrl.class);

	@Autowired
	private IChart chartService;


	/**
	 * 获取订单对照图
	 * @param orgId
	 * @return
     */
	@ResponseBody
	@RequestMapping(value = "/getOrderComparisonChartMsg", method = RequestMethod.GET)
	public ResponseBase<ComparisonChartMsg> getOrderComparisonChartMsg(@RequestParam Integer orgId) {
		ResponseBase<ComparisonChartMsg> resp = new ResponseBase<ComparisonChartMsg>();
		logger.info("进入8080");

		if(orgId == null || orgId == 0){
			orgId = 5;

		}
		ComparisonChartMsg comparisonChartMsg = chartService.getOrderComparisonGraph(orgId);

		if(comparisonChartMsg == null){
			resp.setResult(null);
			resp.setResultCode(ResultCode.PARAM_ERROR.getCode());
			return  resp;
		}

		resp.setResult(comparisonChartMsg);
		resp.setResultCode(ResultCode.SUCC.getCode());
		return resp;
	}


	/**
	 * 获取订单对照图
	 * @param orgId
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/getOrderChartIn", method = RequestMethod.GET)
	public ResponseBase<List<Map<String, Object>>> getOrderChartIn(@RequestParam Integer orgId) {
		ResponseBase<List<Map<String, Object>>> resp = new ResponseBase<List<Map<String, Object>>>();
		logger.info("in getOrderChartIn, orgId={}", orgId);

		if(orgId == null || orgId == 0){
			orgId = 5;
		}

		List<Map<String, Object>> result  = chartService.getOrderIn(orgId);

		if(result  == null){
			resp.setResult(null);
			resp.setResultCode(ResultCode.PARAM_ERROR.getCode());
			return  resp;
		}

		resp.setResult(result);
		resp.setResultCode(ResultCode.SUCC.getCode());
		return resp;
	}

	/**
	 * 获取订单对照图
	 * @param orgId
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/getBrokenLineChartMsg", method = RequestMethod.GET)
	public ResponseBase<BrokenLineChartMsg> getBrokenLineChartMsg(@RequestParam Integer orgId) {
		ResponseBase<BrokenLineChartMsg> resp = new ResponseBase<BrokenLineChartMsg>();
		logger.info("in getBrokenLineChartMsg, orgId={}", orgId);

		if(orgId == null || orgId == 0){
			orgId = 5;
		}

		BrokenLineChartMsg result  = chartService.getOrderBrokenLineGraph(orgId);

		if(result  == null){
			resp.setResult(null);
			resp.setResultCode(ResultCode.PARAM_ERROR.getCode());
			return  resp;
		}

		resp.setResult(result);
		resp.setResultCode(ResultCode.SUCC.getCode());
		return resp;
	}
	 
}
